﻿using System;
using System.Linq;
using System.Reflection;

namespace LOMM3API
{
    public enum GameCommandType
    {
        Unknown,
        NOP,
        SimpleKey,
        Key,
        String,
        CommandChoice,
        ExtendedKey,
        Callback,
        Reminder
    }
    
    [Serializable()]
    public abstract class GameCommandTemplate
    {
        protected Boolean _AllowedInChain = true;
        protected Boolean _AllowedInRandom = true;
        
        public GameCommandType  Type {get; private set;}
        
        public String   Name                {get; private set;}
        public String   ShortDescription    {get; private set;}
        public String   LongDescription     {get; private set;}
        public Boolean  AllowedInChain      {get {return _AllowedInChain;}  private set {return;}}
        public Boolean  AllowedInRandom     {get {return _AllowedInRandom;} private set {return;}}
        public String[] Category            {get; private set;}

        public abstract void   Execute();
        public override string ToString() {return ShortDescription;}
        
        
        public static GameCommandTemplate New(GameCommandType type)
        {
            
            Assembly a = System.Reflection.Assembly.GetAssembly(typeof(GameCommandTemplate));
            var tees = from Type t in a.GetTypes()
                          where (t.IsClass == true)
                          where (t.GetCustomAttributes(true).Contains(type)) 
                          select t;
            if (tees != null && tees.Count() > 0)
            {
                ConstructorInfo ci = tees.First().GetConstructor(System.Type.EmptyTypes);
                return ci.Invoke(null) as GameCommandTemplate;
            }
            return null;
        }
    }

    [LOMMGameCommand(Type = GameCommandType.NOP)]
    public class GameCommandNOP : GameCommandTemplate
    {
        public override void Execute() {return;} // NOP
    }

    [LOMMGameCommand(Type = GameCommandType.SimpleKey)]
    public class GameCommandSimpleKey : GameCommandTemplate
    {
        public override void Execute() {throw new NotImplementedException();}
    }
    [LOMMGameCommand(Type = GameCommandType.Key)]
    public class GameCommandKey : GameCommandTemplate
    {
        public override void Execute() {throw new NotImplementedException();}
    }
    [LOMMGameCommand(Type = GameCommandType.String)]
    public class GameCommandString : GameCommandTemplate
    {
        public override void Execute() {throw new NotImplementedException();}
    }
    [LOMMGameCommand(Type = GameCommandType.CommandChoice)]
    public class GameCommandCommandChoice : GameCommandTemplate
    {
        public override void Execute() {throw new NotImplementedException();}
    }
    [LOMMGameCommand(Type = GameCommandType.ExtendedKey)]
    public class GameCommandExtendedKey : GameCommandTemplate
    {
        public override void Execute() {throw new NotImplementedException();}
    }
    [LOMMGameCommand(Type = GameCommandType.Callback)]
    public class GameCommandCallback : GameCommandTemplate
    {
        public override void Execute() {throw new NotImplementedException();}
    }
    [LOMMGameCommand(Type = GameCommandType.Reminder)]
    public class GameCommandReminder : GameCommandTemplate
    {
        public override void Execute() {throw new NotImplementedException();}
    }
}
